/*
 *  Copyright 2008-2010 the original author or authors.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.openaecfm.spf.io.structuralload;

import org.openaecfm.model.structuralload.StructuralLoad;
import org.openaecfm.model.structuralload.StructuralLoadLinearForce;
import org.openaecfm.spf.io.AbstractEntityInstanceInputImpl;
import org.openaecfm.spf.io.IAppDataManager;
import org.openaecfm.spf.io.IEntityInstanceOutput;
import org.openaecfm.spf.io.IEntityInstanceUtilInput;
import org.openaecfm.spf.io.IEntityInstanceUtilOutput;
import org.openaecfm.spf.model.DollarParameter;
import org.openaecfm.spf.model.EntityInstance;
import org.openaecfm.spf.model.NodeType;
import org.openaecfm.spf.model.Parameter;
import org.openaecfm.spf.model.RealParameter;
import org.openaecfm.spf.model.SimpleEntityInstance;

public final class StructuralLoadLinearForceIO extends
		AbstractEntityInstanceInputImpl<StructuralLoadLinearForce> implements
		IEntityInstanceOutput<StructuralLoadLinearForce> {
	private IEntityInstanceUtilInput<StructuralLoad> utilInput;
	private IEntityInstanceUtilOutput<StructuralLoad> utilOutput;

	public void setUtilOutput(
			IEntityInstanceUtilOutput<StructuralLoad> utilOutput) {
		this.utilOutput = utilOutput;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String exportSPF(StructuralLoadLinearForce pojo,
			IAppDataManager appDataManager) {
		SimpleEntityInstance ei = new SimpleEntityInstance(
				"IFCSTRUCTURALLOADLINEARFORCE", appDataManager.getName(pojo));

		utilOutput.exportSPF(pojo, ei, appDataManager);

		// Set LinearForceX
		if (pojo.getLinearForceX() == null) {
			ei.addParameter(DollarParameter.getInstance());
		} else {
			ei.addParameter(new RealParameter(pojo.getLinearForceX()));
		}

		// Set LinearForceY
		if (pojo.getLinearForceY() == null) {
			ei.addParameter(DollarParameter.getInstance());
		} else {
			ei.addParameter(new RealParameter(pojo.getLinearForceY()));
		}

		// Set LinearForceZ
		if (pojo.getLinearForceZ() == null) {
			ei.addParameter(DollarParameter.getInstance());
		} else {
			ei.addParameter(new RealParameter(pojo.getLinearForceZ()));
		}

		// Set LinearMomentX
		if (pojo.getLinearMomentX() == null) {
			ei.addParameter(DollarParameter.getInstance());
		} else {
			ei.addParameter(new RealParameter(pojo.getLinearMomentX()));
		}

		// Set LinearMomentY
		if (pojo.getLinearMomentY() == null) {
			ei.addParameter(DollarParameter.getInstance());
		} else {
			ei.addParameter(new RealParameter(pojo.getLinearMomentY()));
		}

		// Set LinearMomentZ
		if (pojo.getLinearMomentZ() == null) {
			ei.addParameter(DollarParameter.getInstance());
		} else {
			ei.addParameter(new RealParameter(pojo.getLinearMomentZ()));
		}

		return ei.toString();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected StructuralLoadLinearForce doCreateObject() {
		StructuralLoadLinearForce pojo = new StructuralLoadLinearForce();

		

		return pojo;
	}

	public void setUtilInput(IEntityInstanceUtilInput<StructuralLoad> utilInput) {
		this.utilInput = utilInput;
	}

	@Override
	protected void resolveNotReferenceParameter(EntityInstance ei,
			StructuralLoadLinearForce pojo) {
		utilInput.resolveNotReferenceParameter(ei, pojo);

		SimpleEntityInstance sei = (SimpleEntityInstance) ei;

		// Set LinearForceX
		Parameter lfx = sei.getParameter(1);
		if (lfx.getNodeType() == NodeType.REAL) {
			RealParameter r = (RealParameter) lfx;
			pojo.setLinearForceX(r.toDouble());
		}

		// Set LinearForceY
		Parameter lfy = sei.getParameter(2);
		if (lfy.getNodeType() == NodeType.REAL) {
			RealParameter r = (RealParameter) lfy;
			pojo.setLinearForceY(r.toDouble());
		}

		// Set LinearForceZ
		Parameter lfz = sei.getParameter(3);
		if (lfz.getNodeType() == NodeType.REAL) {
			RealParameter r = (RealParameter) lfz;
			pojo.setLinearForceZ(r.toDouble());
		}

		// Set LinearMomentX
		Parameter lmx = sei.getParameter(4);
		if (lmx.getNodeType() == NodeType.REAL) {
			RealParameter r = (RealParameter) lmx;
			pojo.setLinearMomentX(r.toDouble());
		}

		// Set LinearMomentY
		Parameter lmy = sei.getParameter(5);
		if (lmy.getNodeType() == NodeType.REAL) {
			RealParameter r = (RealParameter) lmy;
			pojo.setLinearMomentY(r.toDouble());
		}

		// Set LinearMomentZ
		Parameter lmz = sei.getParameter(6);
		if (lmz.getNodeType() == NodeType.REAL) {
			RealParameter r = (RealParameter) lmz;
			pojo.setLinearMomentZ(r.toDouble());
		}
	}

	@Override
	public void resolveReferenceParameter(EntityInstance ei,
			StructuralLoadLinearForce pojo, IAppDataManager appDataManager) {
		return ;
	}
}
